﻿using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using T.ApiResults;
using T.Vehicleservice.Domain.Dtos;
using T.Vehicleservice.Domain.T.Vehicleservice.Model;
using T.Vehicleservice.Read.API.Application.Command.ExpenseCommand;
using T.Vehicleservice.Read.API.Application.Command.MaintenanceRecordCommand;

namespace T.Vehicleservice.Read.API.Controllers
{
   /// <summary>
   /// 费用
   /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class ExpenseController : ControllerBase
    {
        private readonly IMediator mediators;

        public ExpenseController(IMediator mediators)
        {
            this.mediators = mediators;
        }
        /// <summary>
        /// 反填费用信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<ExpenseRecord>> ExpenRecord([FromQuery] ExpenseBackfilleCommand command)
        {
            ApiResult<ExpenseRecord> result = new ApiResult<ExpenseRecord>();
            try
            {
                result.Data = await mediators.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;
        }
        /// <summary>
        /// 显示费用记录
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<ApiResult<PageDto<ExpenseRecord>>> ShowExpen([FromQuery] ExpenseShowCommand command)
        {
            ApiResult<PageDto<ExpenseRecord>> result = new ApiResult<PageDto<ExpenseRecord>>();
            try
            {
                result.Data = await mediators.Send(command);
            }
            catch (Exception ex)
            {
                result.Code = -1;
                result.Message = ex.Message;
                throw;
            }
            return result;

        }

    }
}
